package com.ktgj.flight.service.impl;

import com.ktgj.flight.domain.Airliner;
import com.ktgj.flight.domain.FlightAiraccount;
import com.ktgj.flight.mapper.AirlinerMapper;
import com.ktgj.flight.mapper.FlightAiraccountMapper;
import com.ktgj.flight.service.IFlightAiraccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 航司B2B账号Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-12
 */
@Service
public class FlightAiraccountServiceImpl implements IFlightAiraccountService 
{
    @Autowired
    private FlightAiraccountMapper flightAiraccountMapper;
    @Autowired
    private AirlinerMapper airlinerMapper;

    /**
     * 查询航司B2B账号
     * 
     * @param accountId 航司B2B账号ID
     * @return 航司B2B账号
     */
    @Override
    public FlightAiraccount selectFlightAiraccountById(Long accountId)
    {
        return flightAiraccountMapper.selectFlightAiraccountById(accountId);
    }

    /**
     * 查询航司B2B账号列表
     * 
     * @param flightAiraccount 航司B2B账号
     * @return 航司B2B账号
     */
    @Override
    public List<FlightAiraccount> selectFlightAiraccountList(FlightAiraccount flightAiraccount)
    {
        List<FlightAiraccount> flightAiraccounts = flightAiraccountMapper.selectFlightAiraccountList(flightAiraccount);
        if (flightAiraccounts.size() > 0){
            for (FlightAiraccount airaccount : flightAiraccounts) {
                if (airaccount.getAirlinerId() != null){
                    Airliner airliner = airlinerMapper.selectName(airaccount.getAirlinerId());
                    if (airliner != null){
                        airaccount.setAirlinerId(airliner.getAirliner());
                    }
                }
            }
        }
        return flightAiraccounts;
    }

    /**
     * 新增航司B2B账号
     * 
     * @param flightAiraccount 航司B2B账号
     * @return 结果
     */
    @Override
    public int insertFlightAiraccount(FlightAiraccount flightAiraccount)
    {
        return flightAiraccountMapper.insertFlightAiraccount(flightAiraccount);
    }

    /**
     * 修改航司B2B账号
     * 
     * @param flightAiraccount 航司B2B账号
     * @return 结果
     */
    @Override
    public int updateFlightAiraccount(FlightAiraccount flightAiraccount)
    {
        return flightAiraccountMapper.updateFlightAiraccount(flightAiraccount);
    }

    /**
     * 批量删除航司B2B账号
     * 
     * @param accountIds 需要删除的航司B2B账号ID
     * @return 结果
     */
    @Override
    public int deleteFlightAiraccountByIds(Long[] accountIds)
    {
        return flightAiraccountMapper.deleteFlightAiraccountByIds(accountIds);
    }

    /**
     * 删除航司B2B账号信息
     * 
     * @param accountId 航司B2B账号ID
     * @return 结果
     */
    @Override
    public int deleteFlightAiraccountById(Long accountId)
    {
        return flightAiraccountMapper.deleteFlightAiraccountById(accountId);
    }

    /**
     * 根据航司二字码获取对应的账号和密码
     * @param airlinerId
     * @return
     */
    @Override
    public FlightAiraccount selectFlightAirAccountByAirlinerId(String airlinerId) {
        return flightAiraccountMapper.selectFlightAirAccountByAirlinerId(airlinerId);
    }


}
